package com.hiyu.dome3;

import javax.swing.*;
import java.util.Random;

public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;
    String[] boyfaces = {"风流倜傥", "气宇轩昂", "五官端正", "相貌平平", "面部狰狞", "相貌英俊"};
    String[] girlfaces = {"沉鱼落雁", "亭亭玉立", "身材较好", "相貌平平", "惨不忍睹", "美奂绝伦"};
    String[] attacks={
        "%s使出一招[退口水],转到对方身后,一掌%s背心的灵穴排去."
    };
    String[] injure ={
            "结果%s一声惨叫,鲜血狂喷而出."
    };
    public Role() {
    }

    public Role(String name, int blood, char gender,) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        //随机
        setFace(gender);

    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(char gender) {
        Random r = new Random();
        if (gender == '男') {
            int index = r.nextInt(boyfaces.length);
            this.name = boyfaces[index];
        } else if (gender == '女') {
            int index = r.nextInt(girlfaces.length);
            this.name = girlfaces[index];
        } else {
            this.face = "惨不忍睹";
        }
        this.face = face;
    }

    public String[] getBoufaces() {
        return boyfaces;
    }

    public void setBoufaces(String[] boufaces) {
        this.boyfaces = boufaces;
    }

    public String[] getGirlfaces() {
        return girlfaces;
    }

    public void setGirlfaces(String[] girlfaces) {
        this.girlfaces = girlfaces;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    //定义一个方法攻击别人
    public void attack(Role role) {
        Random r = new Random();
        int index = r.nextInt(attacks.length);
        String KongFu = attacks[index];

        System.out.printf(KongFu,this.getName(),role.gam);
        Random r = new Random();

        int hurt = r.nextInt(20) + 1;
        int remainBlood = role.getBlood() - hurt;
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        role.setBlood(remainBlood);

        System.out.println(this.getName() + "举起拳头,打了" + role.getName() + "一下，" +
                "" + "造成了" + hurt + "点伤害," + role.getName() + "还剩下" + remainBlood + "点血量");
    }

    public void showBlood() {
        System.out.println("姓名为:" + getName());
        System.out.println("血量为:" + getBlood());
        System.out.println("性别为:" + getGender());
        System.out.println("长相为:" + getFace());
    }


}
